import { sysCourseUpdate } from "@/api/admin/courseLibrary/sysCourse.js";
import { sysKnowledgeQuery } from "@/api/admin/courseLibrary/sysKnowledge.js";
import { flowApiSubmit } from "@/api/admin/audit/flowApi.js";
import Bus from "@/utils/bus.js";
export const courseAudit = {
  data() {
    return {
      listQuery: {
        page: 1,
        limit: 10,
        courseId: this.row.id,
      },
    };
  },
  methods: {
    //获取知识点数据，判断是否符合发布标准
    getList() {
      return new Promise((resolve, reject) => {
        sysKnowledgeQuery(this.listQuery).then((res) => {
          resolve(res.data.data);
        });
      });
    },
    //审核流程
    handleFlow(row) {
      this.getList().then((res) => {
        if (res.length == 0) {
          this.$message({
            message: "请完善信息",
            type: "warning",
          });
          return;
        }
        
        let definitionCode = this.$store.getters.libraryType;
        flowApiSubmit({
          businessKey: row.id,
          definitionCode,
        }).then((res) => {});
        sysCourseUpdate({
          id: row.id,
          status: 0,
          auditStatus: 4,
        }).then((res) => {
          Bus.$emit("refreshCourseList");
          this.$message({
            message: "操作成功",
            type: "success",
          });
        });
      });
    },
    //发布确认
    handlePublish(row) {
      this.$confirm("确定要提交审核吗?", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
      })
        .then(() => {
          this.publish(row);
        })
        .catch(() => {});
    },
    //提交审核
    publish(row) {
      sysCourseUpdate({
        id: row.id,
        status: 0,
        auditStatus: 1,
      }).then((res) => {
        Bus.$emit("refreshCourseList");
        this.$message({
          message: "操作成功",
          type: "success",
        });
      });
    },
    //取消发布确认
    handleUnPublish(row) {
      this.$confirm("确定要取消发布吗?", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
      })
        .then(() => {
          this.unPublish(row);
        })
        .catch(() => {});
    },
    //取消发布
    unPublish(row) {
      sysCourseUpdate({
        id: row.id,
        status: 0,
        auditStatus: 1,
      }).then((res) => {
        Bus.$emit("refreshCourseList");
        this.$message({
          message: "操作成功",
          type: "success",
        });
      });
    },
  },
};
